package com.happyclub.paul.dao;

import com.happyclub.pojo.TbPersonalPhotoAlbum;
import jdk.internal.org.objectweb.asm.tree.TryCatchBlockNode;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @Auther: 魏泉琦
 * @Date: 2019/4/3 16:04
 * @Description:  用户相册中间
 */
public interface PersonalPhotoAlbumRepostitory extends JpaRepository<TbPersonalPhotoAlbum,String> {


    /**
     *@Description: 当用户创建相册成功后，将用户信息和相册信息保存到用户相册中间表
     *@Author: 魏泉琦
     *@date: 2019/4/3
     */
    @Modifying
    @Query(value = "INSERT into TB_PERSONAL_PHOTO_ALBUM(USER_ID,PHOTO_ALBUM_ID,CREATE_TIME) VALUES(?1,?2,SYSDATE)",nativeQuery = true)
    Integer savePersonalPhotoAlbumMsg(String uid, String photoAlbumId);


    /**
     *@Description: 查询指定用户拥有的所有相册
     *@Author: 魏泉琦
     *@date: 2019/4/6
     */
    @Query(value = "SELECT  USER_ID,PHOTO_ALBUM_ID,CREATE_TIME,UPDATE_TIME  from TB_PERSONAL_PHOTO_ALBUM where USER_ID = ?1",nativeQuery = true)
    List<TbPersonalPhotoAlbum> showUserPhotoAlbum(String userId);


    /**
     *@Description: 根据相册编号删除该用户相册中数据
     *@Author: 魏泉琦
     *@date: 2019/4/6
     */
    @Modifying
    @Query(value = "DELETE from TB_PERSONAL_PHOTO_ALBUM WHERE PHOTO_ALBUM_ID=?1",nativeQuery = true)
    Integer deletePersonalPhotoAlbumByPhotoAlbumId(String photoAlbumId);

}
